package com.taoyi.mhouse.binder;
/**
 * created by tempo on 2015/11/14.
 */

import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.taoy.recyclebinder.DataBindAdapter;
import com.taoy.recyclebinder.DataBinder;
import com.taoyi.mhouse.R;
import com.taoyi.mhouse.bean.HeadLines;
import com.taoyi.mhouse.util.UIUtils;
import com.tempo.widget.SectionBar;

import java.util.ArrayList;
import java.util.List;

;

public class HeadLineBinder extends DataBinder<HeadLineBinder.ViewHolder> {
    private List<HeadLines> data;
    public static int i=0;
    public HeadLineBinder(DataBindAdapter dataBindAdapter) {
        super(dataBindAdapter);
        data=new ArrayList<>();
        for(int i=0;i<10;i++){
            HeadLines headLines=new HeadLines();
            headLines.title=i+"=动漫咨询部=,2015年10月,动漫新番,新番完结简评,你追完了那部剧?";
            data.add(headLines);
        }
    }
    @Override
    public ViewHolder newViewHolder(ViewGroup parent) {
        Log.i(this.getClass().getSimpleName(),""+i++);
        View v = LayoutInflater.from(UIUtils.getContext()).inflate( R.layout.binder_headline,parent,false);
        return new ViewHolder(v);
    }
    @Override
    public void bindViewHolder(ViewHolder holder, int position) {
        holder.tvTitle.setText(data.get(position).title);
        holder.iv.setImageResource(R.drawable.a1);
        if(position==0){
            holder.mSectionBar.setVisibility(View.VISIBLE);
            holder.mSectionBar.setOnSectionBarClickListtener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(UIUtils.getContext(),"head line clicked:"+i,Toast.LENGTH_SHORT).show();
                }
            });

        }else{
            holder.mSectionBar.setOnSectionBarClickListtener(null);
            holder.mSectionBar.setVisibility(View.GONE);
        }
    }
    @Override
    public int getItemCount() {
        return data.size();
    }
    static class ViewHolder extends RecyclerView.ViewHolder{
        public TextView tvTitle;
        public ImageView iv;
        public SectionBar mSectionBar;
        public ViewHolder(View itemView) {
            super(itemView);
            tvTitle = (TextView) itemView.findViewById(R.id.tv_headline_title);
            iv = (ImageView) itemView.findViewById(R.id.iv_headline);
            mSectionBar = (SectionBar) itemView.findViewById(R.id.sectionbar);
        }
    }
}
